/**
 * 给定01字符串，每次操作可以交换相邻位置。
 * 问最少多少次操作可以使得字符串相邻位置不同，保证有解
 * 枚举2次，第一次以0开头，第二次以1开头
 * 有解且次数少的就是答案
 */
#include <bits/stdc++.h>
using namespace std;

using llt = long long;
using pii = pair<int, int>;
using pll = pair<llt, llt>;
using vi = vector<int>;
using vvi = vector<vi>;
using int128 = __int128_t;

string S;

llt proc(const string & s){
    llt ans = 0;
    int n = s.length();
    int k = 0;
    char cur = s[0];
    while(k < n and s[k] == cur) ++k;
    int nowL = k;

    while(k < n){
        int nextL = 0;
        char another = '1' ^ '0' ^ cur;
        while(k < n and s[k] == another){
            ++k;
            ++nextL;
        }

        if(nowL >= nextL){
            ans += (0LL + nowL - 1 + nowL - nextL) * nextL / 2LL;
            nowL -= nextL;
            while(k < n and s[k] == cur){
                ++k;
                ++nowL;
            }
        }else{
            ans += (0LL + nowL - 1) * nowL / 2LL;
            nowL = nextL - nowL + 1;
            cur = another;
        }
    }
    if(nowL <= 1) return ans;
    return -1;
}

llt proc(){
    int n = S.length();
    if(n <= 2) return 0;

    llt ans = proc(S);
    
    char cur = S[0];
    int k = 0;
    while(k < n and S[k] == cur) ++k;

    string s(1, S[k]);
    s.insert(s.end(), S.begin(), S.begin() + k);
    s.insert(s.end(), S.begin()+k+1, S.end());

    llt tmp = proc(s);
    if(tmp != -1) tmp += k;
    if(-1 == ans){
        ans = tmp;
    }else if(-1 != tmp and tmp < ans){
        ans = tmp;
    }

    reverse(S.begin(), S.end());
    tmp = proc(S);    
    if(-1 == ans){
        ans = tmp;
    }else if(-1 != tmp and tmp < ans){
        ans = tmp;
    }

    cur = S[0];
    k = 0;
    while(k < n and S[k] == cur) ++k;
    
    s.assign(1, S[k]);
    s.insert(s.end(), S.begin(), S.begin() + k);
    s.insert(s.end(), S.begin()+k+1, S.end());

    tmp = proc(s);
    if(tmp != -1) tmp += k;
    if(-1 == ans){
        ans = tmp;
    }else if(-1 != tmp and tmp < ans){
        ans = tmp;
    }

    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> S;
    cout << proc() << endl;
    return 0;
}

